'use strict'
let nunjucks=require('nunjucks');

function creatConf(path,opts) {
    path=path||'html';
    opts=opts||{}
    let conf={
        autoescape :opts.autoescape || true,
        throwOnUndefined :opts.throwOnUndefined || false,
        trimBlocks : opts.trimBlocks || false,
        lstripBlocks :opts.lstripBlocks || false,
        watch :opts.watch||true,
        noCache :opts.noCache || true
    }
    let env=nunjucks.configure('html',conf)
    return env;
}

module.exports=async(etc,next)=>{
    let env=creatConf();
    etc.render=function (path,opts) {
        etc.body=env.render(path,opts) 
    }
    await next();
}